package com.ytjj.qmyx.admin.model.request;

import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Data
public class CustomerNewRequest extends PageRequest {

    private Integer orderInfoId;//订单详情id

    private String orderNo;//订单号

    private Integer productId;//商品id

    private Integer payType;//支付类型

    private String userName;//收货人姓名

    private String userPhone;//收货人手机号

    private Integer isPay;//支付状态

    private String orderInfoStatus;//订单状态

    private String bankerName;//供应商名称

    private Date startTime;//开始时间

    private Date endTime;//结束时间

    private String childOrderNo;// 子订单id

    private String resOrderNo;//支付订单号

    private String buyer;

    /**
     * 供应商id集合
     */
    private List<Integer> bankerIds;

    /**
     * 收款账号
     */
    private String account;

    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;//地址相等
        }

        if(obj == null){
            return false;//非空性：对于任意非空引用x，x.equals(null)应该返回false。
        }

        if(obj instanceof CustomerNewRequest){
            CustomerNewRequest other = (CustomerNewRequest) obj;
            //需要比较的字段相等，则这两个对象相等
            if(equalsStr(this.bankerName, other.bankerName)
                    && equalsInteger(this.orderInfoId, other.orderInfoId)
                    && equalsStr(this.orderNo, other.orderNo)
                    && equalsInteger(this.productId, other.productId)
                    && equalsInteger(this.payType, other.payType)
                    && equalsStr(this.userName, other.userName)
                    && equalsStr(this.userPhone, other.userPhone)
                    && equalsInteger(this.isPay, other.isPay)
                    && equalsStr(this.orderInfoStatus, other.orderInfoStatus)
                    && equalsDate(this.startTime, other.startTime)
                    && equalsDate(this.endTime, other.endTime)
                    && equalsStr(this.childOrderNo, other.childOrderNo)
                    && equalsStr(this.resOrderNo, other.resOrderNo)
                    && equalsList(this.bankerIds, other.bankerIds)){
                return true;
            }
        }

        return false;
    }

    private boolean equalsStr(String str1, String str2){
        if(StringUtils.isEmpty(str1) && StringUtils.isEmpty(str2)){
            return true;
        }
        if(!StringUtils.isEmpty(str1) && str1.equals(str2)){
            return true;
        }
        return false;
    }

    private boolean equalsInteger(Integer val1, Integer val2) {
        if (null == val1 && null == val2) {
            return true;
        }
        if (null != val1 && val1.equals(val2)) {
            return true;
        }
        return false;
    }

    private boolean equalsDate(Date val1, Date val2) {
        if (null == val1 && null == val2) {
            return true;
        }
        if (null != val1 && null != val2 && val1.getTime() == val2.getTime()) {
            return true;
        }
        return false;
    }

    private boolean equalsList(List val1, List val2) {
        if (CollectionUtils.isEmpty(val1) && CollectionUtils.isEmpty(val2)) {
            return true;
        }
        if (!CollectionUtils.isEmpty(val1) && !CollectionUtils.isEmpty(val2)) {
            if (val1.size() != val2.size()) {
                return false;
            }
            if (val1.containsAll(val2)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + (bankerName == null ? 0 : bankerName.hashCode());
        result = 31 * result + (orderInfoId == null ? 0 : orderInfoId.hashCode());
        result = 31 * result + (orderNo == null ? 0 : orderNo.hashCode());
        result = 31 * result + (productId == null ? 0 : productId.hashCode());
        result = 31 * result + (payType == null ? 0 : payType.hashCode());
        result = 31 * result + (userName == null ? 0 : userName.hashCode());
        result = 31 * result + (userPhone == null ? 0 : userPhone.hashCode());
        result = 31 * result + (isPay == null ? 0 : isPay.hashCode());
        result = 31 * result + (orderInfoStatus == null ? 0 : isPay.hashCode());
        result = 31 * result + (startTime == null ? 0 : startTime.hashCode());
        result = 31 * result + (endTime == null ? 0 : endTime.hashCode());
        result = 31 * result + (childOrderNo == null ? 0 : childOrderNo.hashCode());
        result = 31 * result + (resOrderNo == null ? 0 : resOrderNo.hashCode());
        result = 31 * result + (bankerIds == null ? 0 : bankerIds.hashCode());
        result = 31 * result + (pageNum == null ? 0 : pageNum.hashCode());
        return result;
    }
}
